package com.example.demo1.controller;

import com.example.demo1.service.DiscountService;
import com.example.demo1.service.SmallGiftService;
import com.example.demo1.service.YouKuMemberService;
import com.example.demo1.service.impl.DiscountServiceImpl;
import com.example.demo1.service.impl.SmallGiftServiceImpl;
import com.example.demo1.service.impl.YouKuMemberServiceImpl;
import com.example.entity.AwardInfo;
import com.example.entity.ResponseResult;

public class AwardInfoController {

    /**
     * 代码 不符合开闭原则 没有扩展性
     * <p>
     * 模拟 用户注册完后  参加抽奖活动  其中  awardType 代表用户参与的活动
     * 这里使用的是 硬编码的方式 直接实现的  后面用工厂模式 进行优化
     */
    public static void sendPrizes(AwardInfo awardInfo) {
        if (awardInfo.getAwardType() == 1) {
            //发送打折卷
            DiscountService discountService = new DiscountServiceImpl();
            ResponseResult responseResult = discountService.sendDiscount(awardInfo);
            System.out.println("discountInfo = " + responseResult.toString());
        } else if (awardInfo.getAwardType() == 2) {
            //优酷会员
            YouKuMemberService discountService = new YouKuMemberServiceImpl();
            ResponseResult responseResult = discountService.sendYoukuMembers(awardInfo);
            System.out.println("discountInfo = " + responseResult.toString());
        } else if (awardInfo.getAwardType() == 3) {
            SmallGiftService discountService = new SmallGiftServiceImpl();
            ResponseResult responseResult = discountService.sendSmallGift(awardInfo);
            System.out.println("discountInfo = " + responseResult.toString());
        }
    }

    public static void main(String[] args) {
        AwardInfo awardInfo = new AwardInfo();
        awardInfo.setUid("1111");
        awardInfo.setAwardType(2);
        awardInfo.setAwardNumber("23131313");
        awardInfo.setExtMap(null);

        sendPrizes(awardInfo);

    }

}
